/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.com.jsepc.rep.process;

import cn.com.jsepc.rep.comm.ConstUtil;
import cn.com.jsepc.rep.vo.Relate_RepVO;
import cn.com.jsepc.rep.vo.ReportVO;
import com.jarp.db.DAO;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Vector;
import net.sf.json.JSONArray;

/**
 *
 * @author 赵远
 */
public class Process_relate {

    public String getProcessGrid(String start, String limit, String KeyWord_0,
            String KeyWord_1, String KeyWord_2, String KeyWord_3,
            String KeyWord_4, String KeyWord_5, String id) {
        String [] myid=id.split("_");
        id=myid[myid.length-1];
        String res = "";
        DAO dao = new DAO();
        try {
            List<ReportVO> lstResults = new ArrayList<ReportVO>();
            int iStart = Integer.parseInt(start);
            int iPageSize = Integer.parseInt(limit);
            int iCurPage = iStart / iPageSize + 1;
            StringBuffer str = new StringBuffer();
            str.append("select a.*,t.processid,c.cataname,e.name  from (select * from TB_REPORT a where ISVALID = 1 ");

            if (KeyWord_5 != null && !KeyWord_5.equals("")) {
                //点击树根节点的情况
                if (KeyWord_5.equals("0")) {
                    if (KeyWord_0 != null && !KeyWord_0.equals("")) {
                        str.append(" and a.REPNAME like '%" + KeyWord_0 + "%'");
                    }
                    if (KeyWord_1 != null && !KeyWord_1.equals("") && !KeyWord_1.equals("101")) {
                        str.append(" and a.DEPARTMENT = '" + KeyWord_1 + "'");
                    }
                    if (KeyWord_2 != null && !KeyWord_2.equals("")) {
                        if (KeyWord_2.equals("3")) {
                        } else {
                            str.append(" and a.SOURCETYPE = " + KeyWord_2);
                        }
                    }
                    if (KeyWord_3 != null && !KeyWord_3.equals("")) {
                        if (KeyWord_3.equals("6")) {
                        } else {
                            str.append(" and a.DATATYPE = " + KeyWord_3);
                        }
                    }
                    if (KeyWord_4 != null && !KeyWord_4.equals("")) {
                        if (KeyWord_4.equals("7")) {
                        } else {
                            str.append(" and a.UPDATETIME = " + KeyWord_4);
                        }
                    }
                } //点击树子节点的情况
                else {
                    if (KeyWord_0 != null && !KeyWord_0.equals("")) {
                        str.append(" and a.REPNAME like '%" + KeyWord_0 + "%'");
                    }
                    if (KeyWord_1 != null && !KeyWord_1.equals("") && !KeyWord_1.equals("101")) {
                        str.append(" and a.DEPARTMENT = '" + KeyWord_1 + "' ");
                    }
                    if (KeyWord_2 != null && !KeyWord_2.equals("")) {
                        if (KeyWord_2.equals("3")) {
                        } else {
                            str.append(" and a.SOURCETYPE = " + KeyWord_2);
                        }
                    }
                    if (KeyWord_3 != null && !KeyWord_3.equals("")) {
                        if (KeyWord_3.equals("6")) {
                        } else {
                            str.append(" and a.DATATYPE = " + KeyWord_3);
                        }
                    }
                    if (KeyWord_4 != null && !KeyWord_4.equals("")) {
                        if (KeyWord_4.equals("7")) {
                        } else {
                            str.append(" and a.UPDATETIME = " + KeyWord_4);
                        }
                    }
                    if (KeyWord_5 != null && !KeyWord_5.equals("")) {
                        str.append(" and a.CATAID = " + KeyWord_5);
                    }
                }
            } //未点击树的情况
            else {
                if (KeyWord_0 != null && !KeyWord_0.equals("")) {
                    str.append(" and REPNAME like '%" + KeyWord_0 + "%'");
                }
                if (KeyWord_1 != null && !KeyWord_1.equals("") && !KeyWord_1.equals("101")) {
                    str.append(" and DEPARTMENT = '" + KeyWord_1 + "'");
                }
                if (KeyWord_2 != null && !KeyWord_2.equals("")) {
                    if (KeyWord_2.equals("3")) {
                    } else {
                        str.append(" and SOURCETYPE = " + KeyWord_2);
                    }
                }
                if (KeyWord_3 != null && !KeyWord_3.equals("")) {
                    if (KeyWord_3.equals("6")) {
                    } else {
                        str.append(" and DATATYPE = " + KeyWord_3);
                    }
                }
                if (KeyWord_4 != null && !KeyWord_4.equals("")) {
                    if (KeyWord_4.equals("7")) {
                    } else {
                        str.append(" and UPDATETIME = " + KeyWord_4);
                    }
                }
                if (KeyWord_5 != null && !KeyWord_5.equals("")) {
                    str.append(" and a.CATAID = " + KeyWord_5);
                }
            }
            str.append(" ) a");
            str.append(" left join tb_process_rep t on t.processid=" + id + " and t.repid = a.repid");
            str.append(" left join TB_CATALOG c on c.CATAID = a.CATAID");
            str.append(" left join tb_process d on d.processID=t.processID");
            str.append(" left join TB_CORP_DEPT e on e.ID=a.DEPARTMENT ");

//			str.append(" where rn between " + iStart + " and " + iEnd);
            Vector v = dao.getDataSet(ConstUtil.DBNAME, str.toString(), iCurPage, iPageSize);
            if (v != null) {
                for (int i = 0; i < v.size(); i++) {
                    Hashtable hashRows = (Hashtable) v.get(i);
                    ReportVO repVO = new ReportVO();
                    repVO.setRepid((String) hashRows.get("REPID"));
                    repVO.setRepcode((String) hashRows.get("REPCODE"));
                    repVO.setRepname((String) hashRows.get("REPNAME"));
                    repVO.setCataid((String) hashRows.get("CATANAME"));
                    repVO.setRepdesc((String) hashRows.get("REPDESC"));
                    repVO.setDesc((String) hashRows.get("CALDESC"));
                    repVO.setDataprec((String) hashRows.get("DATAPREC"));
                    repVO.setDataunit((String) hashRows.get("DATAUNIT"));
                    repVO.setDepartmentid((String) hashRows.get("DEPARTMENT"));
                    repVO.setDepartment((String) hashRows.get("NAME"));
                    repVO.setSourcetype((String) hashRows.get("SOURCETYPE"));
                    repVO.setDatatype((String) hashRows.get("DATATYPE"));
                    repVO.setUpdatetime((String) hashRows.get("UPDATETIME"));
                    repVO.setReffact((String) hashRows.get("REFFACT"));
                    repVO.setRepvaluecol((String) hashRows.get("REPVALUECOL"));
                    repVO.setIsselect((String) hashRows.get("PROCESSID"));
                    lstResults.add(repVO);

                }
            }
            JSONArray json = new JSONArray();
            StringBuffer str1 = new StringBuffer();
            str1.append("select count(1) CNT from TB_REPORT where ISVALID = 1 ");
            if (KeyWord_5 != null && !KeyWord_5.equals("")) {
                //点击树根节点的情况
                if (KeyWord_5.equals("0")) {
                    if (KeyWord_0 != null && !KeyWord_0.equals("")) {
                        str1.append(" and REPNAME like '%" + KeyWord_0 + "%'");
                    }
                    if (KeyWord_1 != null && !KeyWord_1.equals("") && !KeyWord_1.equals("101")) {
                        str1.append(" and DEPARTMENT = '" + KeyWord_1 + "'");
                    }
                    if (KeyWord_2 != null && !KeyWord_2.equals("")) {
                        if (KeyWord_2.equals("3")) {
                        } else {
                            str1.append(" and SOURCETYPE = " + KeyWord_2);
                        }
                    }
                    if (KeyWord_3 != null && !KeyWord_3.equals("")) {
                        if (KeyWord_3.equals("6")) {
                        } else {
                            str1.append(" and DATATYPE = " + KeyWord_3);
                        }
                    }
                    if (KeyWord_4 != null && !KeyWord_4.equals("")) {
                        if (KeyWord_4.equals("7")) {
                        } else {
                            str1.append(" and UPDATETIME = " + KeyWord_4);
                        }
                    }
                } //点击树子节点的情况
                else {
                    if (KeyWord_0 != null && !KeyWord_0.equals("")) {
                        str1.append(" and REPNAME like '%" + KeyWord_0 + "%' and CATAID = " + KeyWord_5);
                    }
                    if (KeyWord_1 != null && !KeyWord_1.equals("") && !KeyWord_1.equals("101")) {
                        str1.append(" and DEPARTMENT = '" + KeyWord_1 + "' and CATAID = " + KeyWord_5);
                    }
                    if (KeyWord_2 != null && !KeyWord_2.equals("")) {
                        if (KeyWord_2.equals("3")) {
                        } else {
                            str1.append(" and SOURCETYPE = " + KeyWord_2 + " and CATAID = " + KeyWord_5);
                        }
                    }
                    if (KeyWord_3 != null && !KeyWord_3.equals("")) {
                        if (KeyWord_3.equals("6")) {
                        } else {
                            str1.append(" and DATATYPE = " + KeyWord_3 + " and CATAID = " + KeyWord_5);
                        }
                    }
                    if (KeyWord_4 != null && !KeyWord_4.equals("")) {
                        if (KeyWord_4.equals("7")) {
                        } else {
                            str1.append(" and UPDATETIME = " + KeyWord_4 + " and CATAID = " + KeyWord_5);
                        }
                    }
                    if (KeyWord_5 != null && !KeyWord_5.equals("")) {
                        str1.append(" and CATAID = " + KeyWord_5);
                    }
                }
            } //未点击树的情况
            else {
                if (KeyWord_0 != null && !KeyWord_0.equals("")) {
                    str1.append(" and REPNAME like '%" + KeyWord_0 + "%'");
                }
                if (KeyWord_1 != null && !KeyWord_1.equals("") && !KeyWord_1.equals("101")) {
                    str1.append(" and DEPARTMENT = '" + KeyWord_1 + "'");
                }
                if (KeyWord_2 != null && !KeyWord_2.equals("")) {
                    if (KeyWord_2.equals("3")) {
                    } else {
                        str1.append(" and SOURCETYPE = " + KeyWord_2);
                    }
                }
                if (KeyWord_3 != null && !KeyWord_3.equals("")) {
                    if (KeyWord_3.equals("6")) {
                    } else {
                        str1.append(" and DATATYPE = " + KeyWord_3);
                    }
                }
                if (KeyWord_4 != null && !KeyWord_4.equals("")) {
                    if (KeyWord_4.equals("7")) {
                    } else {
                        str1.append(" and UPDATETIME = " + KeyWord_4);
                    }
                }
                if (KeyWord_5 != null && !KeyWord_5.equals("")) {
                    str1.append(" and CATAID = " + KeyWord_5);
                }
            }
            String totalCount = dao.getDataValue(ConstUtil.DBNAME, str1.toString());
            json = JSONArray.fromObject(lstResults);
            res = "{totalCount:" + totalCount + ",data:" + json.toString()
                    + "}";
            //System.out.println(res);
        } catch (Exception ex) {
            ex.printStackTrace();
            System.out.println("NewProjectTree getXmDl Exception.");
        }
        return res;
    }

    public String get_process(String start, String limit, String id) {
        String [] myid=id.split("_");
        id=myid[myid.length-1];
        String res = "";
        DAO dao = new DAO();
        try {
            List<Relate_RepVO> lstResults = new ArrayList<Relate_RepVO>();
            int iStart = Integer.parseInt(start);
            int iPageSize = Integer.parseInt(limit);
            int iPage = iStart / iPageSize + 1;
            StringBuffer str = new StringBuffer();
            str.append("select * from tb_process_rep a" + " left join tb_report b on b.repID=a.repID" + " left join tb_process c on c.processID=a.processID" + " left join TB_CATALOG d on d.cataid=b.cataid " + "where a.processid=").append(id);
            Vector v = dao.getDataSet(ConstUtil.DBNAME, str.toString(), iPage, iPageSize);
            if (v != null) {
                for (int i = 0; i < v.size(); i++) {
                    Hashtable hashRows = (Hashtable) v.get(i);
                    Relate_RepVO repVO = new Relate_RepVO();
                    repVO.setRepid((String) hashRows.get("REPID"));
                    repVO.setRepcode((String) hashRows.get("REPCODE"));
                    repVO.setRepname((String) hashRows.get("REPNAME"));
                    repVO.setCataname((String) hashRows.get("CATANAME"));

                    lstResults.add(repVO);
                }
            }
            JSONArray json = new JSONArray();
            StringBuffer str1 = new StringBuffer();
            str1.append("select count(1) CNT from tb_process_rep where processID=" + id);
            String totalCount = dao.getDataValue(ConstUtil.DBNAME, str1.toString());
            json = JSONArray.fromObject(lstResults);
            res = "{totalCount:" + totalCount + ",data:" + json.toString()
                    + "}";
        } catch (Exception ex) {
            ex.printStackTrace();
            System.out.println("NewProjectTree getXmDl Exception.");
        }
        return res;
    }
    
    public String get_process_all(String start, String limit,String mytreeid) {

        String res = "";
        DAO dao = new DAO();
        try {
            List<Relate_RepVO> lstResults = new ArrayList<Relate_RepVO>();
            int iStart = Integer.parseInt(start);
            int iPageSize = Integer.parseInt(limit);
            int iPage = iStart / iPageSize + 1;
            StringBuffer str = new StringBuffer();
            str.append("select * from tb_process_rep a" + " left join tb_report b on b.repID=a.repID" + " left join tb_process c on c.processID=a.processID" + " left join TB_CATALOG d on d.cataid=b.cataid ");
            Vector v = dao.getDataSet(ConstUtil.DBNAME, str.toString(), iPage, iPageSize);
            if (v != null) {
                for (int i = 0; i < v.size(); i++) {
                    Hashtable hashRows = (Hashtable) v.get(i);
                    Relate_RepVO repVO = new Relate_RepVO();
                    repVO.setRepid((String) hashRows.get("REPID"));
                    repVO.setRepcode((String) hashRows.get("REPCODE"));
                    repVO.setRepname((String) hashRows.get("REPNAME"));
                    repVO.setCataname((String) hashRows.get("CATANAME"));
                    repVO.setProcessid((String) hashRows.get("PROCESSID"));
                    repVO.setProcessname((String) hashRows.get("PROCESSNAME"));
                    lstResults.add(repVO);
                }
            }
            JSONArray json = new JSONArray();
            StringBuffer str1 = new StringBuffer();
            str1.append("select count(1) CNT from tb_process_rep where 1 = 1 ");
            String totalCount = dao.getDataValue(ConstUtil.DBNAME, str1.toString());
            json = JSONArray.fromObject(lstResults);
            res = "{totalCount:" + totalCount + ",data:" + json.toString()
                    + "}";
        } catch (Exception ex) {
            ex.printStackTrace();
            System.out.println("NewProjectTree getXmDl Exception.");
        }
        return res;
    }

    public String get_process_query(String start, String limit, String id, String repcode, String repname) {
        String [] myid=id.split("_");
        id=myid[myid.length-1];
        String res = "";
        DAO dao = new DAO();
        try {
            List<Relate_RepVO> lstResults = new ArrayList<Relate_RepVO>();
            int iStart = Integer.parseInt(start);
            int iPageSize = Integer.parseInt(limit);
            int iPage = iStart / iPageSize + 1;
            StringBuffer str = new StringBuffer();
            if (repcode.equals("") && repname.equals("")) {
                str.append("select * from tb_process_rep a" + " left join tb_report b on b.repID=a.repID" + " left join tb_process c on c.processID=a.processID" + " left join TB_CATALOG d on d.cataid=b.cataid " + "where a.processid=").append(id);
            } else if (repcode.equals("")) {
                str.append("select * from tb_process_rep a" + " left join tb_report b on b.repID=a.repID" + " left join tb_process c on c.processID=a.processID" + " left join TB_CATALOG d on d.cataid=b.cataid " + "where a.processid=").append(id).append(" and b.repname like '%").append(repname).append("%'");
            } else if (repname.equals("")) {
                str.append("select * from tb_process_rep a" + " left join tb_report b on b.repID=a.repID" + " left join tb_process c on c.processID=a.processID" + " left join TB_CATALOG d on d.cataid=b.cataid " + "where a.processid=").append(id).append(" and  b.repcode like '%").append(repcode).append("%'");
            }
            //    str.append("select * from tb_process_rep a" + " left join tb_report b on b.repID=a.repID" + " left join tb_process c on c.processID=a.processID" + " left join TB_CATALOG d on d.cataid=b.cataid " + "where a.processid=").append(id).append(" and b.repcode like '").append(repcode).append("' or b.repname like '").append(repname).append("'");
            Vector v = dao.getDataSet(ConstUtil.DBNAME, str.toString(), iPage, iPageSize);
            if (v != null) {
                for (int i = 0; i < v.size(); i++) {
                    Hashtable hashRows = (Hashtable) v.get(i);
                    Relate_RepVO repVO = new Relate_RepVO();
                    repVO.setRepid((String) hashRows.get("REPID"));
                    repVO.setRepcode((String) hashRows.get("REPCODE"));
                    repVO.setRepname((String) hashRows.get("REPNAME"));
                    repVO.setCataname((String) hashRows.get("CATANAME"));

                    lstResults.add(repVO);
                }
            }
            JSONArray json = new JSONArray();
            String []str_sql=str.toString().split("from");
            String my_sql=str_sql[str_sql.length-1];
            StringBuffer str1 = new StringBuffer();
            str1.append("select count(1) CNT from "+my_sql);
            String totalCount = dao.getDataValue(ConstUtil.DBNAME, str1.toString());
            json = JSONArray.fromObject(lstResults);
            res = "{totalCount:" + totalCount + ",data:" + json.toString()
                    + "}";
        } catch (Exception ex) {
            ex.printStackTrace();
            System.out.println("NewProjectTree getXmDl Exception.");
        }
        return res;
    }
    
    public String get_process_query_all(String start, String limit, String repcode, String repname) {
        String res = "";
        DAO dao = new DAO();
        try {
            List<Relate_RepVO> lstResults = new ArrayList<Relate_RepVO>();
            int iStart = Integer.parseInt(start);
            int iPageSize = Integer.parseInt(limit);
            int iPage = iStart / iPageSize + 1;
            StringBuffer str = new StringBuffer();
            if (repcode.equals("") && repname.equals("")) {
                str.append("select * from tb_process_rep a" + " left join tb_report b on b.repID=a.repID" + " left join tb_process c on c.processID=a.processID" + " left join TB_CATALOG d on d.cataid=b.cataid ");
            } else if (repcode.equals("")) {
                str.append("select * from tb_process_rep a" + " left join tb_report b on b.repID=a.repID" + " left join tb_process c on c.processID=a.processID" + " left join TB_CATALOG d on d.cataid=b.cataid where b.repname like '%").append(repname).append("%'");
            } else if (repname.equals("")) {
                str.append("select * from tb_process_rep a" + " left join tb_report b on b.repID=a.repID" + " left join tb_process c on c.processID=a.processID" + " left join TB_CATALOG d on d.cataid=b.cataid  where  b.repcode like '%").append(repcode).append("%'");
            }
            //    str.append("select * from tb_process_rep a" + " left join tb_report b on b.repID=a.repID" + " left join tb_process c on c.processID=a.processID" + " left join TB_CATALOG d on d.cataid=b.cataid " + "where a.processid=").append(id).append(" and b.repcode like '").append(repcode).append("' or b.repname like '").append(repname).append("'");
            Vector v = dao.getDataSet(ConstUtil.DBNAME, str.toString(), iPage, iPageSize);
            if (v != null) {
                for (int i = 0; i < v.size(); i++) {
                    Hashtable hashRows = (Hashtable) v.get(i);
                    Relate_RepVO repVO = new Relate_RepVO();
                    repVO.setRepid((String) hashRows.get("REPID"));
                    repVO.setRepcode((String) hashRows.get("REPCODE"));
                    repVO.setRepname((String) hashRows.get("REPNAME"));
                    repVO.setCataname((String) hashRows.get("CATANAME"));
                    repVO.setProcessname((String) hashRows.get("PROCESSNAME"));
                    lstResults.add(repVO);
                }
            }
            JSONArray json = new JSONArray();
            String []str_sql=str.toString().split("from");
            String my_sql=str_sql[str_sql.length-1];
            StringBuffer str1 = new StringBuffer();
            str1.append("select count(1) CNT from "+my_sql);
            String totalCount = dao.getDataValue(ConstUtil.DBNAME, str1.toString());
            json = JSONArray.fromObject(lstResults);
            res = "{totalCount:" + totalCount + ",data:" + json.toString()
                    + "}";
        } catch (Exception ex) {
            ex.printStackTrace();
            System.out.println("NewProjectTree getXmDl Exception.");
        }
        return res;
    }

    public String getLinkGrid(String start, String limit, String KeyWord_0,
            String KeyWord_1, String KeyWord_2, String KeyWord_3,
            String KeyWord_4, String KeyWord_5, String id) {
        String [] myid=id.split("_");
        id=myid[myid.length-1];
        String res = "";
        DAO dao = new DAO();
        try {
            List<ReportVO> lstResults = new ArrayList<ReportVO>();
            int iStart = Integer.parseInt(start);
            int iPageSize = Integer.parseInt(limit);
            int iCurPage = iStart / iPageSize + 1;
            StringBuffer str = new StringBuffer();
            str.append("select a.*,t.linkid,c.cataname,d.*,e.name  from (select * from TB_REPORT a where ISVALID = 1 ");

            if (KeyWord_5 != null && !KeyWord_5.equals("")) {
                //点击树根节点的情况
                if (KeyWord_5.equals("0")) {
                    if (KeyWord_0 != null && !KeyWord_0.equals("")) {
                        str.append(" and a.REPNAME like '%" + KeyWord_0 + "%'");
                    }
                    if (KeyWord_1 != null && !KeyWord_1.equals("") && !KeyWord_1.equals("101")) {
                        str.append(" and a.DEPARTMENT = '" + KeyWord_1 + "'");
                    }
                    if (KeyWord_2 != null && !KeyWord_2.equals("")) {
                        if (KeyWord_2.equals("3")) {
                        } else {
                            str.append(" and a.SOURCETYPE = " + KeyWord_2);
                        }
                    }
                    if (KeyWord_3 != null && !KeyWord_3.equals("")) {
                        if (KeyWord_3.equals("6")) {
                        } else {
                            str.append(" and a.DATATYPE = " + KeyWord_3);
                        }
                    }
                    if (KeyWord_4 != null && !KeyWord_4.equals("")) {
                        if (KeyWord_4.equals("7")) {
                        } else {
                            str.append(" and a.UPDATETIME = " + KeyWord_4);
                        }
                    }
                } //点击树子节点的情况
                else {
                    if (KeyWord_0 != null && !KeyWord_0.equals("")) {
                        str.append(" and a.REPNAME like '%" + KeyWord_0 + "%'");
                    }
                    if (KeyWord_1 != null && !KeyWord_1.equals("") && !KeyWord_1.equals("101")) {
                        str.append(" and a.DEPARTMENT = '" + KeyWord_1 + "' ");
                    }
                    if (KeyWord_2 != null && !KeyWord_2.equals("")) {
                        if (KeyWord_2.equals("3")) {
                        } else {
                            str.append(" and a.SOURCETYPE = " + KeyWord_2);
                        }
                    }
                    if (KeyWord_3 != null && !KeyWord_3.equals("")) {
                        if (KeyWord_3.equals("6")) {
                        } else {
                            str.append(" and a.DATATYPE = " + KeyWord_3);
                        }
                    }
                    if (KeyWord_4 != null && !KeyWord_4.equals("")) {
                        if (KeyWord_4.equals("7")) {
                        } else {
                            str.append(" and a.UPDATETIME = " + KeyWord_4);
                        }
                    }
                    if (KeyWord_5 != null && !KeyWord_5.equals("")) {
                        str.append(" and a.CATAID = " + KeyWord_5);
                    }
                }
            } //未点击树的情况
            else {
                if (KeyWord_0 != null && !KeyWord_0.equals("")) {
                    str.append(" and REPNAME like '%" + KeyWord_0 + "%'");
                }
                if (KeyWord_1 != null && !KeyWord_1.equals("") && !KeyWord_1.equals("101")) {
                    str.append(" and DEPARTMENT = '" + KeyWord_1 + "'");
                }
                if (KeyWord_2 != null && !KeyWord_2.equals("")) {
                    if (KeyWord_2.equals("3")) {
                    } else {
                        str.append(" and SOURCETYPE = " + KeyWord_2);
                    }
                }
                if (KeyWord_3 != null && !KeyWord_3.equals("")) {
                    if (KeyWord_3.equals("6")) {
                    } else {
                        str.append(" and DATATYPE = " + KeyWord_3);
                    }
                }
                if (KeyWord_4 != null && !KeyWord_4.equals("")) {
                    if (KeyWord_4.equals("7")) {
                    } else {
                        str.append(" and UPDATETIME = " + KeyWord_4);
                    }
                }
                if (KeyWord_5 != null && !KeyWord_5.equals("")) {
                    str.append(" and a.CATAID = " + KeyWord_5);
                }
            }
            str.append(" ) a");
            str.append(" left join tb_link_rep t on t.linkid=" + id + " and t.repid = a.repid");
            str.append(" left join TB_CATALOG c on c.CATAID = a.CATAID");
            str.append(" left join tb_link d on d.linkID=t.linkid");
            str.append(" left join TB_CORP_DEPT e on e.ID=a.DEPARTMENT ");

//			str.append(" where rn between " + iStart + " and " + iEnd);
            Vector v = dao.getDataSet(ConstUtil.DBNAME, str.toString(), iCurPage, iPageSize);
            if (v != null) {
                for (int i = 0; i < v.size(); i++) {
                    Hashtable hashRows = (Hashtable) v.get(i);
                    ReportVO repVO = new ReportVO();
                    repVO.setRepid((String) hashRows.get("REPID"));
                    repVO.setRepcode((String) hashRows.get("REPCODE"));
                    repVO.setRepname((String) hashRows.get("REPNAME"));
                    repVO.setCataid((String) hashRows.get("CATANAME"));
                    repVO.setRepdesc((String) hashRows.get("REPDESC"));
                    repVO.setDesc((String) hashRows.get("CALDESC"));
                    repVO.setDataprec((String) hashRows.get("DATAPREC"));
                    repVO.setDataunit((String) hashRows.get("DATAUNIT"));
                    repVO.setDepartmentid((String) hashRows.get("DEPARTMENT"));
                    repVO.setDepartment((String) hashRows.get("NAME"));
                    repVO.setSourcetype((String) hashRows.get("SOURCETYPE"));
                    repVO.setDatatype((String) hashRows.get("DATATYPE"));
                    repVO.setUpdatetime((String) hashRows.get("UPDATETIME"));
                    repVO.setReffact((String) hashRows.get("REFFACT"));
                    repVO.setRepvaluecol((String) hashRows.get("REPVALUECOL"));
                    repVO.setIsselect((String) hashRows.get("LINKID"));
                    lstResults.add(repVO);

                }
            }
            JSONArray json = new JSONArray();
            StringBuffer str1 = new StringBuffer();
            str1.append("select count(1) CNT from TB_REPORT where ISVALID = 1 ");
            if (KeyWord_5 != null && !KeyWord_5.equals("")) {
                //点击树根节点的情况
                if (KeyWord_5.equals("0")) {
                    if (KeyWord_0 != null && !KeyWord_0.equals("")) {
                        str1.append(" and REPNAME like '%" + KeyWord_0 + "%'");
                    }
                    if (KeyWord_1 != null && !KeyWord_1.equals("") && !KeyWord_1.equals("101")) {
                        str1.append(" and DEPARTMENT = '" + KeyWord_1 + "'");
                    }
                    if (KeyWord_2 != null && !KeyWord_2.equals("")) {
                        if (KeyWord_2.equals("3")) {
                        } else {
                            str1.append(" and SOURCETYPE = " + KeyWord_2);
                        }
                    }
                    if (KeyWord_3 != null && !KeyWord_3.equals("")) {
                        if (KeyWord_3.equals("6")) {
                        } else {
                            str1.append(" and DATATYPE = " + KeyWord_3);
                        }
                    }
                    if (KeyWord_4 != null && !KeyWord_4.equals("")) {
                        if (KeyWord_4.equals("7")) {
                        } else {
                            str1.append(" and UPDATETIME = " + KeyWord_4);
                        }
                    }
                } //点击树子节点的情况
                else {
                    if (KeyWord_0 != null && !KeyWord_0.equals("")) {
                        str1.append(" and REPNAME like '%" + KeyWord_0 + "%' and CATAID = " + KeyWord_5);
                    }
                    if (KeyWord_1 != null && !KeyWord_1.equals("") && !KeyWord_1.equals("101")) {
                        str1.append(" and DEPARTMENT = '" + KeyWord_1 + "' and CATAID = " + KeyWord_5);
                    }
                    if (KeyWord_2 != null && !KeyWord_2.equals("")) {
                        if (KeyWord_2.equals("3")) {
                        } else {
                            str1.append(" and SOURCETYPE = " + KeyWord_2 + " and CATAID = " + KeyWord_5);
                        }
                    }
                    if (KeyWord_3 != null && !KeyWord_3.equals("")) {
                        if (KeyWord_3.equals("6")) {
                        } else {
                            str1.append(" and DATATYPE = " + KeyWord_3 + " and CATAID = " + KeyWord_5);
                        }
                    }
                    if (KeyWord_4 != null && !KeyWord_4.equals("")) {
                        if (KeyWord_4.equals("7")) {
                        } else {
                            str1.append(" and UPDATETIME = " + KeyWord_4 + " and CATAID = " + KeyWord_5);
                        }
                    }
                    if (KeyWord_5 != null && !KeyWord_5.equals("")) {
                        str1.append(" and CATAID = " + KeyWord_5);
                    }
                }
            } //未点击树的情况
            else {
                if (KeyWord_0 != null && !KeyWord_0.equals("")) {
                    str1.append(" and REPNAME like '%" + KeyWord_0 + "%'");
                }
                if (KeyWord_1 != null && !KeyWord_1.equals("") && !KeyWord_1.equals("101")) {
                    str1.append(" and DEPARTMENT = '" + KeyWord_1 + "'");
                }
                if (KeyWord_2 != null && !KeyWord_2.equals("")) {
                    if (KeyWord_2.equals("3")) {
                    } else {
                        str1.append(" and SOURCETYPE = " + KeyWord_2);
                    }
                }
                if (KeyWord_3 != null && !KeyWord_3.equals("")) {
                    if (KeyWord_3.equals("6")) {
                    } else {
                        str1.append(" and DATATYPE = " + KeyWord_3);
                    }
                }
                if (KeyWord_4 != null && !KeyWord_4.equals("")) {
                    if (KeyWord_4.equals("7")) {
                    } else {
                        str1.append(" and UPDATETIME = " + KeyWord_4);
                    }
                }
                if (KeyWord_5 != null && !KeyWord_5.equals("")) {
                    str1.append(" and CATAID = " + KeyWord_5);
                }
            }
            String totalCount = dao.getDataValue(ConstUtil.DBNAME, str1.toString());
            json = JSONArray.fromObject(lstResults);
            res = "{totalCount:" + totalCount + ",data:" + json.toString()
                    + "}";
            //System.out.println(res);
        } catch (Exception ex) {
            ex.printStackTrace();
            System.out.println("NewProjectTree getXmDl Exception.");
        }
        return res;
    }

    public String get_link(String start, String limit, String id) {
        String [] myid=id.split("_");
        id=myid[myid.length-1];
        String res = "";
        DAO dao = new DAO();
        try {
            List<Relate_RepVO> lstResults = new ArrayList<Relate_RepVO>();
            int iStart = Integer.parseInt(start);
            int iPageSize = Integer.parseInt(limit);
            int iPage = iStart / iPageSize + 1;
            StringBuffer str = new StringBuffer();
            str.append("select * from tb_link_rep a left join tb_report b on b.repid=a.repid left join tb_link c on c.linkid=a.linkid left join TB_CATALOG d on d.cataid=b.cataid where a.linkid=").append(id);
            Vector v = dao.getDataSet(ConstUtil.DBNAME, str.toString(), iPage, iPageSize);
            if (v != null) {
                for (int i = 0; i < v.size(); i++) {
                    Hashtable hashRows = (Hashtable) v.get(i);
                    Relate_RepVO repVO = new Relate_RepVO();
                    repVO.setRepid((String) hashRows.get("REPID"));
                    repVO.setRepcode((String) hashRows.get("REPCODE"));
                    repVO.setRepname((String) hashRows.get("REPNAME"));
                    repVO.setCataname((String) hashRows.get("CATANAME"));

                    lstResults.add(repVO);
                }
            }
            JSONArray json = new JSONArray();
            StringBuffer str1 = new StringBuffer();
            str1.append("select count(1) CNT from tb_link_rep where linkid= "+id);
            String totalCount = dao.getDataValue(ConstUtil.DBNAME, str1.toString());
            json = JSONArray.fromObject(lstResults);
            res = "{totalCount:" + totalCount + ",data:" + json.toString()
                    + "}";
        } catch (Exception ex) {
            ex.printStackTrace();
            System.out.println("NewProjectTree getXmDl Exception.");
        }
        return res;
    }

    public String get_link_query(String start, String limit, String id, String repcode, String repname) {
        String [] myid=id.split("_");
        id=myid[myid.length-1];
        String res = "";
        DAO dao = new DAO();
        try {
            List<Relate_RepVO> lstResults = new ArrayList<Relate_RepVO>();
            int iStart = Integer.parseInt(start);
            int iPageSize = Integer.parseInt(limit);
            int iPage = iStart / iPageSize + 1;
            StringBuffer str = new StringBuffer();
            if (repcode.equals("") && repname.equals("")) {
                str.append("select * from tb_link_rep a left join tb_report b on b.repid=a.repid left join tb_link c on c.linkid=a.linkid left join TB_CATALOG d on d.cataid=b.cataid where a.linkid=").append(id);
            } else if (repcode.equals("")) {
                str.append("select * from tb_link_rep a left join tb_report b on b.repid=a.repid left join tb_link c on c.linkid=a.linkid left join TB_CATALOG d on d.cataid=b.cataid where a.linkid=").append(id).append(" and b.repname like '%").append(repname).append("%'");
            } else if (repname.equals("")) {
                str.append("select * from tb_link_rep a left join tb_report b on b.repid=a.repid left join tb_link c on c.linkid=a.linkid left join TB_CATALOG d on d.cataid=b.cataid where a.linkid=").append(id).append(" and b.repcode like '%").append(repcode).append("%'");
            }
            Vector v = dao.getDataSet(ConstUtil.DBNAME, str.toString(), iPage, iPageSize);
            if (v != null) {
                for (int i = 0; i < v.size(); i++) {
                    Hashtable hashRows = (Hashtable) v.get(i);
                    Relate_RepVO repVO = new Relate_RepVO();
                    repVO.setRepid((String) hashRows.get("REPID"));
                    repVO.setRepcode((String) hashRows.get("REPCODE"));
                    repVO.setRepname((String) hashRows.get("REPNAME"));
                    repVO.setCataname((String) hashRows.get("CATANAME"));

                    lstResults.add(repVO);
                }
            }
            JSONArray json = new JSONArray();
            String []str_sql=str.toString().split("from");
            String my_sql=str_sql[str_sql.length-1];
            StringBuffer str1 = new StringBuffer();
            str1.append("select count(1) CNT from "+my_sql);
            String totalCount = dao.getDataValue(ConstUtil.DBNAME, str1.toString());
            json = JSONArray.fromObject(lstResults);
            res = "{totalCount:" + totalCount + ",data:" + json.toString()
                    + "}";
        } catch (Exception ex) {
            ex.printStackTrace();
            System.out.println("NewProjectTree getXmDl Exception.");
        }
        return res;
    }

    public String getPointGrid(String start, String limit, String KeyWord_0,
            String KeyWord_1, String KeyWord_2, String KeyWord_3,
            String KeyWord_4, String KeyWord_5, String id) {
        String [] myid=id.split("_");
        id=myid[myid.length-1];
        String res = "";
        DAO dao = new DAO();
        try {
            List<ReportVO> lstResults = new ArrayList<ReportVO>();
            int iStart = Integer.parseInt(start);
            int iPageSize = Integer.parseInt(limit);
            int iCurPage = iStart / iPageSize + 1;
            StringBuffer str = new StringBuffer();
            str.append("select a.*,t.pointid,c.cataname,d.*,e.name  from (select * from TB_REPORT a where ISVALID = 1 ");

            if (KeyWord_5 != null && !KeyWord_5.equals("")) {
                //点击树根节点的情况
                if (KeyWord_5.equals("0")) {
                    if (KeyWord_0 != null && !KeyWord_0.equals("")) {
                        str.append(" and a.REPNAME like '%" + KeyWord_0 + "%'");
                    }
                    if (KeyWord_1 != null && !KeyWord_1.equals("") && !KeyWord_1.equals("101")) {
                        str.append(" and a.DEPARTMENT = '" + KeyWord_1 + "'");
                    }
                    if (KeyWord_2 != null && !KeyWord_2.equals("")) {
                        if (KeyWord_2.equals("3")) {
                        } else {
                            str.append(" and a.SOURCETYPE = " + KeyWord_2);
                        }
                    }
                    if (KeyWord_3 != null && !KeyWord_3.equals("")) {
                        if (KeyWord_3.equals("6")) {
                        } else {
                            str.append(" and a.DATATYPE = " + KeyWord_3);
                        }
                    }
                    if (KeyWord_4 != null && !KeyWord_4.equals("")) {
                        if (KeyWord_4.equals("7")) {
                        } else {
                            str.append(" and a.UPDATETIME = " + KeyWord_4);
                        }
                    }
                } //点击树子节点的情况
                else {
                    if (KeyWord_0 != null && !KeyWord_0.equals("")) {
                        str.append(" and a.REPNAME like '%" + KeyWord_0 + "%'");
                    }
                    if (KeyWord_1 != null && !KeyWord_1.equals("") && !KeyWord_1.equals("101")) {
                        str.append(" and a.DEPARTMENT = '" + KeyWord_1 + "' ");
                    }
                    if (KeyWord_2 != null && !KeyWord_2.equals("")) {
                        if (KeyWord_2.equals("3")) {
                        } else {
                            str.append(" and a.SOURCETYPE = " + KeyWord_2);
                        }
                    }
                    if (KeyWord_3 != null && !KeyWord_3.equals("")) {
                        if (KeyWord_3.equals("6")) {
                        } else {
                            str.append(" and a.DATATYPE = " + KeyWord_3);
                        }
                    }
                    if (KeyWord_4 != null && !KeyWord_4.equals("")) {
                        if (KeyWord_4.equals("7")) {
                        } else {
                            str.append(" and a.UPDATETIME = " + KeyWord_4);
                        }
                    }
                    if (KeyWord_5 != null && !KeyWord_5.equals("")) {
                        str.append(" and a.CATAID = " + KeyWord_5);
                    }
                }
            } //未点击树的情况
            else {
                if (KeyWord_0 != null && !KeyWord_0.equals("")) {
                    str.append(" and REPNAME like '%" + KeyWord_0 + "%'");
                }
                if (KeyWord_1 != null && !KeyWord_1.equals("") && !KeyWord_1.equals("101")) {
                    str.append(" and DEPARTMENT = '" + KeyWord_1 + "'");
                }
                if (KeyWord_2 != null && !KeyWord_2.equals("")) {
                    if (KeyWord_2.equals("3")) {
                    } else {
                        str.append(" and SOURCETYPE = " + KeyWord_2);
                    }
                }
                if (KeyWord_3 != null && !KeyWord_3.equals("")) {
                    if (KeyWord_3.equals("6")) {
                    } else {
                        str.append(" and DATATYPE = " + KeyWord_3);
                    }
                }
                if (KeyWord_4 != null && !KeyWord_4.equals("")) {
                    if (KeyWord_4.equals("7")) {
                    } else {
                        str.append(" and UPDATETIME = " + KeyWord_4);
                    }
                }
                if (KeyWord_5 != null && !KeyWord_5.equals("")) {
                    str.append(" and a.CATAID = " + KeyWord_5);
                }
            }
            str.append(" ) a");
            str.append(" left join tb_point_rep t on t.pointid=" + id + " and t.repid = a.repid");
            str.append(" left join TB_CATALOG c on c.CATAID = a.CATAID");
            str.append(" left join tb_point d on d.linkID=t.pointID");
            str.append(" left join TB_CORP_DEPT e on e.ID=a.DEPARTMENT ");

//			str.append(" where rn between " + iStart + " and " + iEnd);
            Vector v = dao.getDataSet(ConstUtil.DBNAME, str.toString(), iCurPage, iPageSize);
            if (v != null) {
                for (int i = 0; i < v.size(); i++) {
                    Hashtable hashRows = (Hashtable) v.get(i);
                    ReportVO repVO = new ReportVO();
                    repVO.setRepid((String) hashRows.get("REPID"));
                    repVO.setRepcode((String) hashRows.get("REPCODE"));
                    repVO.setRepname((String) hashRows.get("REPNAME"));
                    repVO.setCataid((String) hashRows.get("CATANAME"));
                    repVO.setRepdesc((String) hashRows.get("REPDESC"));
                    repVO.setDesc((String) hashRows.get("CALDESC"));
                    repVO.setDataprec((String) hashRows.get("DATAPREC"));
                    repVO.setDataunit((String) hashRows.get("DATAUNIT"));
                    repVO.setDepartmentid((String) hashRows.get("DEPARTMENT"));
                    repVO.setDepartment((String) hashRows.get("NAME"));
                    repVO.setSourcetype((String) hashRows.get("SOURCETYPE"));
                    repVO.setDatatype((String) hashRows.get("DATATYPE"));
                    repVO.setUpdatetime((String) hashRows.get("UPDATETIME"));
                    repVO.setReffact((String) hashRows.get("REFFACT"));
                    repVO.setRepvaluecol((String) hashRows.get("REPVALUECOL"));
                    repVO.setIsselect((String) hashRows.get("POINTID"));
                    lstResults.add(repVO);

                }
            }
            JSONArray json = new JSONArray();
            StringBuffer str1 = new StringBuffer();
            str1.append("select count(1) CNT from TB_REPORT where ISVALID = 1 ");
            if (KeyWord_5 != null && !KeyWord_5.equals("")) {
                //点击树根节点的情况
                if (KeyWord_5.equals("0")) {
                    if (KeyWord_0 != null && !KeyWord_0.equals("")) {
                        str1.append(" and REPNAME like '%" + KeyWord_0 + "%'");
                    }
                    if (KeyWord_1 != null && !KeyWord_1.equals("") && !KeyWord_1.equals("101")) {
                        str1.append(" and DEPARTMENT = '" + KeyWord_1 + "'");
                    }
                    if (KeyWord_2 != null && !KeyWord_2.equals("")) {
                        if (KeyWord_2.equals("3")) {
                        } else {
                            str1.append(" and SOURCETYPE = " + KeyWord_2);
                        }
                    }
                    if (KeyWord_3 != null && !KeyWord_3.equals("")) {
                        if (KeyWord_3.equals("6")) {
                        } else {
                            str1.append(" and DATATYPE = " + KeyWord_3);
                        }
                    }
                    if (KeyWord_4 != null && !KeyWord_4.equals("")) {
                        if (KeyWord_4.equals("7")) {
                        } else {
                            str1.append(" and UPDATETIME = " + KeyWord_4);
                        }
                    }
                } //点击树子节点的情况
                else {
                    if (KeyWord_0 != null && !KeyWord_0.equals("")) {
                        str1.append(" and REPNAME like '%" + KeyWord_0 + "%' and CATAID = " + KeyWord_5);
                    }
                    if (KeyWord_1 != null && !KeyWord_1.equals("") && !KeyWord_1.equals("101")) {
                        str1.append(" and DEPARTMENT = '" + KeyWord_1 + "' and CATAID = " + KeyWord_5);
                    }
                    if (KeyWord_2 != null && !KeyWord_2.equals("")) {
                        if (KeyWord_2.equals("3")) {
                        } else {
                            str1.append(" and SOURCETYPE = " + KeyWord_2 + " and CATAID = " + KeyWord_5);
                        }
                    }
                    if (KeyWord_3 != null && !KeyWord_3.equals("")) {
                        if (KeyWord_3.equals("6")) {
                        } else {
                            str1.append(" and DATATYPE = " + KeyWord_3 + " and CATAID = " + KeyWord_5);
                        }
                    }
                    if (KeyWord_4 != null && !KeyWord_4.equals("")) {
                        if (KeyWord_4.equals("7")) {
                        } else {
                            str1.append(" and UPDATETIME = " + KeyWord_4 + " and CATAID = " + KeyWord_5);
                        }
                    }
                    if (KeyWord_5 != null && !KeyWord_5.equals("")) {
                        str1.append(" and CATAID = " + KeyWord_5);
                    }
                }
            } //未点击树的情况
            else {
                if (KeyWord_0 != null && !KeyWord_0.equals("")) {
                    str1.append(" and REPNAME like '%" + KeyWord_0 + "%'");
                }
                if (KeyWord_1 != null && !KeyWord_1.equals("") && !KeyWord_1.equals("101")) {
                    str1.append(" and DEPARTMENT = '" + KeyWord_1 + "'");
                }
                if (KeyWord_2 != null && !KeyWord_2.equals("")) {
                    if (KeyWord_2.equals("3")) {
                    } else {
                        str1.append(" and SOURCETYPE = " + KeyWord_2);
                    }
                }
                if (KeyWord_3 != null && !KeyWord_3.equals("")) {
                    if (KeyWord_3.equals("6")) {
                    } else {
                        str1.append(" and DATATYPE = " + KeyWord_3);
                    }
                }
                if (KeyWord_4 != null && !KeyWord_4.equals("")) {
                    if (KeyWord_4.equals("7")) {
                    } else {
                        str1.append(" and UPDATETIME = " + KeyWord_4);
                    }
                }
                if (KeyWord_5 != null && !KeyWord_5.equals("")) {
                    str1.append(" and CATAID = " + KeyWord_5);
                }
            }
            //    System.out.println(str1.toString());
            String totalCount = dao.getDataValue(ConstUtil.DBNAME, str1.toString());
            json = JSONArray.fromObject(lstResults);
            res = "{totalCount:" + totalCount + ",data:" + json.toString()
                    + "}";
            //System.out.println(res);
        } catch (Exception ex) {
            ex.printStackTrace();
            System.out.println("NewProjectTree getXmDl Exception.");
        }
        return res;
    }

    public String get_point(String start, String limit, String id) {
        String [] myid=id.split("_");
        id=myid[myid.length-1];
        String res = "";
        DAO dao = new DAO();
        try {
            List<Relate_RepVO> lstResults = new ArrayList<Relate_RepVO>();
            int iStart = Integer.parseInt(start);
            int iPageSize = Integer.parseInt(limit);
            int iPage = iStart / iPageSize + 1;
            StringBuffer str = new StringBuffer();
            str.append("select * from tb_point_rep a left join tb_report b on b.repID=a.repID left join tb_point c on c.linkID=a.pointID left join TB_CATALOG d on d.cataid=b.cataid where a.pointid=").append(id);
            Vector v = dao.getDataSet(ConstUtil.DBNAME, str.toString(), iPage, iPageSize);
            if (v != null) {
                for (int i = 0; i < v.size(); i++) {
                    Hashtable hashRows = (Hashtable) v.get(i);
                    Relate_RepVO repVO = new Relate_RepVO();
                    repVO.setRepid((String) hashRows.get("REPID"));
                    repVO.setRepcode((String) hashRows.get("REPCODE"));
                    repVO.setRepname((String) hashRows.get("REPNAME"));
                    repVO.setCataname((String) hashRows.get("CATANAME"));

                    lstResults.add(repVO);
                }
            }
            JSONArray json = new JSONArray();
            StringBuffer str1 = new StringBuffer();
            str1.append("select count(1) CNT from tb_point_rep where pointid= "+id);
            String totalCount = dao.getDataValue(ConstUtil.DBNAME, str1.toString());
            json = JSONArray.fromObject(lstResults);
            res = "{totalCount:" + totalCount + ",data:" + json.toString()
                    + "}";
        } catch (Exception ex) {
            ex.printStackTrace();
            System.out.println("NewProjectTree getXmDl Exception.");
        }
        return res;
    }

    public String get_point_query(String start, String limit, String id, String repcode, String repname) {
        String [] myid=id.split("_");
        id=myid[myid.length-1];
        String res = "";
        DAO dao = new DAO();
        try {
            List<Relate_RepVO> lstResults = new ArrayList<Relate_RepVO>();
            int iStart = Integer.parseInt(start);
            int iPageSize = Integer.parseInt(limit);
            int iPage = iStart / iPageSize + 1;
            StringBuffer str = new StringBuffer();
            if (repcode.equals("") && repname.equals("")) {
            }
            if (repcode.equals("") && repname.equals("")) {
                str.append("select * from tb_point_rep a left join tb_report b on b.repID=a.repID left join tb_point c on c.linkID=a.pointID left join TB_CATALOG d on d.cataid=b.cataid where a.pointid=").append(id);
            } else if (repcode.equals("")) {
                str.append("select * from tb_point_rep a left join tb_report b on b.repID=a.repID left join tb_point c on c.linkID=a.pointID left join TB_CATALOG d on d.cataid=b.cataid where a.pointid=").append(id).append(" and  b.repname like '%").append(repname).append("%'");
            } else if (repname.equals("")) {
                str.append("select * from tb_point_rep a left join tb_report b on b.repID=a.repID left join tb_point c on c.linkID=a.pointID left join TB_CATALOG d on d.cataid=b.cataid where a.pointid=").append(id).append(" and b.repcode like '%").append(repcode).append("%'");
            }
            Vector v = dao.getDataSet(ConstUtil.DBNAME, str.toString(), iPage, iPageSize);
            if (v != null) {
                for (int i = 0; i < v.size(); i++) {
                    Hashtable hashRows = (Hashtable) v.get(i);
                    Relate_RepVO repVO = new Relate_RepVO();
                    repVO.setRepid((String) hashRows.get("REPID"));
                    repVO.setRepcode((String) hashRows.get("REPCODE"));
                    repVO.setRepname((String) hashRows.get("REPNAME"));
                    repVO.setCataname((String) hashRows.get("CATANAME"));

                    lstResults.add(repVO);
                }
            }
            JSONArray json = new JSONArray();
            String []str_sql=str.toString().split("from");
            String my_sql=str_sql[str_sql.length-1];
            StringBuffer str1 = new StringBuffer();
            str1.append("select count(1) CNT from "+my_sql);
            String totalCount = dao.getDataValue(ConstUtil.DBNAME, str1.toString());
            json = JSONArray.fromObject(lstResults);
            res = "{totalCount:" + totalCount + ",data:" + json.toString()
                    + "}";
        } catch (Exception ex) {
            ex.printStackTrace();
            System.out.println("NewProjectTree getXmDl Exception.");
        }
        return res;
    }
}
